#include "games/buttongame.h"

ButtonGame::ButtonGame(QWidget *parent, int difflvl) :
    BaseGame(parent, difflvl)
{
    n_rows = 10;
    n_cols = 10;

    map = new QPushButton**[n_rows];
    for(int r = 0; r < n_rows; r++) {
        map[r] = new QPushButton*[n_cols];
        lay->setRowMinimumHeight(r, 20);

        for(int c = 0; c < n_cols; c++) {
            lay->setColumnMinimumWidth(c, 20);
            QPushButton * p = new QPushButton(this);
            map[r][c] = p;
            lay->addWidget(p, r, c);
            connect(p,SIGNAL(clicked()), this, SLOT(onButtonClicked()));
            p->hide();
        }
    }
    int r = qrand() % n_rows;
    int c = qrand() % n_cols;
    map[r][c]->show();
    current_button = map[r][c];

    counter = 0;
}

void ButtonGame::onButtonClicked()
{
    counter++;
    current_button->hide();
    int r = qrand() % n_rows;
    int c = qrand() % n_cols;
    map[r][c]->show();
    current_button = map[r][c];
}
